package com.miao.im.service.message;

import lombok.Data;

import java.time.ZoneOffset;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/4/24 20:17
 * @Description:
 */
@Data
public class OfflineMessageCounter {
    /**离线消息数量*/
    private Integer count;
    private ChatMessage lastMsg;
    /**最后一条消息的时间*/
    private Long timestamp;

    public OfflineMessageCounter() {
    }

    public OfflineMessageCounter(ChatMessage chatMessage) {
        this.count = 1;
        this.lastMsg = chatMessage;
        this.timestamp = chatMessage.getSendTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }

    public void incCount() {
        this.count += 1;
    }

    /**
     * @Description: 更新最后一条消息
     * @Author: miaoguoxin
     * @Date: 2021/4/24
     */
    public void update(ChatMessage chatMessage) {
        this.lastMsg = chatMessage;
        this.count += 1;
        this.timestamp = chatMessage.getSendTime().toInstant(ZoneOffset.of("+8")).toEpochMilli();
    }
}
